#ifndef SEMANTICINFO_H
#define SEMANTICINFO_H

#include "../js_lib/parser/qmljsast_p.h"
#include "../js_lib/qmljsscopechain.h"
#include "../js_lib/qmljsstaticanalysismessage.h"

#include <QTextCursor>

class Range
{
public:
    Range(): ast(0) {}

public: // attributes
    QmlJS::AST::Node *ast;
    QTextCursor begin;
    QTextCursor end;
};

class SemanticInfo
{
public:
    SemanticInfo() {}
    SemanticInfo(QmlJS::ScopeChain *rootScopeChain);

    bool isValid() const;
    int revision() const;

    QList<QmlJS::AST::Node *> astPath(int cursorPosition) const;

    QmlJS::AST::Node *astNodeAt(int cursorPosition) const;

    QList<QmlJS::AST::Node *> rangePath(int cursorPosition) const;

    QmlJS::AST::Node *rangeAt(int cursorPosition) const;
    QmlJS::AST::Node *declaringMemberNoProperties(int cursorPosition) const;

    QmlJS::ScopeChain scopeChain(const QList<QmlJS::AST::Node *> &path = QList<QmlJS::AST::Node *>()) const;

    void setRootScopeChain(QSharedPointer<const QmlJS::ScopeChain> rootScopeChain);

public:
    QmlJS::Document::Ptr document;
    QmlJS::Snapshot snapshot;
    QmlJS::ContextPtr context;
    QList<Range> ranges;
    QHash<QString, QList<QmlJS::AST::SourceLocation> > idLocations;

    QList<QmlJS::DiagnosticMessage> semanticMessages;
    QList<QmlJS::StaticAnalysis::Message> staticAnalysisMessages;

private:
    QSharedPointer<const QmlJS::ScopeChain> m_rootScopeChain;
};
Q_DECLARE_METATYPE(SemanticInfo)

#endif // SEMANTICINFO_H
